<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<!DOCTYPE html>
<html xmlns:th="" lang="zh-CN">
<%@include file="/WEB-INF/pages/base/include.jsp"%>
<body>
<div id="wrapper">
    <%@include file="/WEB-INF/pages/base/menu.jsp"%>
    <div id="page-wrapper">
        <div class="row">
            <div class="col-lg-12">
                <h3 class="page-header">账号管理</h3>
            </div>
        </div>
        <div class="row">
            <form class="form-horizontal" data-parsley-validate>
                <div class="col-lg-12 col-md-12">
                    <div class="panel panel-default">
                        <div class="panel-heading">账号编辑</div>
                        <div class="panel-body">
                            <div class="row">
                                <div class="col-lg-12 col-md-12">
                                    <div class="form-group">
                                         <label class="col-lg-2 clo-md-2 control-label">账号id：</label>
                                         <div class="col-lg-8">
                                         	 <p id="managerId" ></p>
                                         </div>
                                     </div>
                                     <div class="form-group">
                                         <label class="col-lg-2 clo-md-2 control-label">所属商城：</label>
                                         <div class="col-lg-8">
                                         	 <p id="mallName" ></p>
                                         </div>
                                     </div>
                                     <div class="form-group">
                                         <label class="col-lg-2 clo-md-2 control-label" >账号名：</label>
                                         <div class="col-lg-8">
                                             <input type="text" id="name" value="" onkeyup = "ValidateValue(this)">
                                         </div>
                                     </div>
                                     <div class="form-group">
                                         <label class="col-lg-2 clo-md-2 control-label" >密码：</label>
                                         <div class="col-lg-8">
                                         	 <input type="password" id="pwd" value="" onkeyup = "ValidateValue(this)">
                                       	</div>
                                  	 </div>
                                     <div class="form-group">
                                         <label class="col-lg-2 clo-md-2 control-label" >确认密码：</label>
                                         <div class="col-lg-8">
                                         	 <input type="password" id="pwd2" value="" onkeyup = "ValidateValue(this)">
                                       	</div>
                                  	 </div>
                                  	 <div class="form-group">
                                         <label class="col-lg-2 clo-md-2 control-label">创建时间：</label>
                                         <div class="col-lg-8">
                                             <p id="createTime" ></p>
                                       	</div>
                                  	 </div>
                                   </div>
                               </div>
                           </div>
                       </div>
                   <div class="clearfix"></div>
                   <a class="btn btn-primary" href="javascript:void(0);"
                      style="margin-left:15px;margin-bottom:30px;" onclick="modify()">完成</a>
                   <a class="btn btn-default" href="${webPath}toManager"
                      style="margin-left:15px;margin-bottom:30px;">取消</a>
                </div>
            </form>
        </div>
    </div>
</div>
<script>
	function ValidateValue(textbox) {
		var IllegalString = "[`~!#$^&*()=|{}':;',\\[\\].<>/?~！#￥……&*（）——|{}【】‘；：”“'。，、？-+@&%_]‘’";
		var textboxvalue = textbox.value;
		var index = textboxvalue.length - 1;
		var s = textbox.value.charAt(index);
		if (IllegalString.indexOf(s) >= 0) {
			s = textboxvalue.substring(0, index);
			textbox.value = s;
		}
	}

   	$(function(){
		var managerId = "${managerId}";
  		var baseURL = "${webPath}/manager/detail";
      	var json_package = {
           "head": {},
           "body": {
           	"managerId": managerId
           }
       	}
   		$.post(baseURL, {"json_package": JSON.stringify(json_package)}, function (result) {
          if (typeof result == 'string') result = JSON.parse(result);
          if (result.body.result == '1') {
              alert(result.body.description)
          } else {
          	var manager = result.body.manager;
          	$("#managerId").text(manager.managerId);
          	$("#mallName").text(manager.mallName);
          	$("#name").val(manager.name);
          	//$("#pwd").val(manager.pwd);
          	$("#createTime").text(manager.createTime);
          }
      	})
   	});

   	function modify() {

   		var type = "${type}";
		if(type == "3"){
			alert("当前账号无权限查看此功能");
			return;
		}

   		var managerId = "${managerId}";
   		var name = $("#name").val();
      	var pwd = $("#pwd").val();
        var pwd2 = $("#pwd2").val();
        if(pwd!= pwd2){
            alert('两次输入密码不同，请确认密码');
            return;
        }
  		var baseURL = "${webPath}/manager/modify";
      	var json_package = {
           "head": {},
           "body": {
           	"managerId": managerId,
           	"name": name,
           	"pwd": pwd
           }
       	}
   		$.post(baseURL, {"json_package": JSON.stringify(json_package)}, function (result) {
          if (typeof result == 'string') result = JSON.parse(result);
          if (result.body.result == '1') {
              alert(result.body.description)
          } else {
        	  alert(result.body.description)
        	  location.href = "${webPath}toManager";
          }
      	})
	}
</script>
</body>
</html>
